﻿using System.Collections.Generic;
using nRoute.SiteMaps;
using nRoute.ViewModels;

namespace nRoute.Samples.SimpleMVVM.ViewModels
{
#if (SILVERLIGHT)
    [MapViewModel(typeof(MainPage))]
#else
    [MapViewModel(typeof(MainWindow))]
#endif
    public class MainPageViewModel
        : ViewModelBase
    {
        public MainPageViewModel()
        {
            LoadSiteMap();
        }

        public IEnumerable<SiteMapNode> SiteMapNodes { get; private set; }

        private void LoadSiteMap()
        {
            // load the site-map, note we load it asynchronously 
            SiteMapService.LoadSiteMap((s) =>
            {
                this.SiteMapNodes = s.RootNode.ChildNodes;
                NotifyPropertyChanged(() => SiteMapNodes);
            });
        }
    }
}
